package com.wing.cabinet.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.cabinet.model.entity.Cabinet;
import com.wing.cabinet.model.entity.CabinetLoadPlan;
import com.wing.cabinet.model.entity.CabinetLoadPlanDetail;
import com.wing.cabinet.model.request.CabinetLoadPlanForm;
import com.wing.cabinet.model.response.*;
import com.wing.cabinet.service.CabinetCargoLaneService;
import com.wing.cabinet.service.CabinetLoadPlanDetailService;
import com.wing.cabinet.service.CabinetLoadPlanService;
import com.wing.cabinet.service.CabinetService;
import com.wing.common.exception.BusinessException;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.order.model.entity.DistributionDemand;
import com.wing.order.model.response.DistributionDemandDetailVO;
import com.wing.order.model.response.DistributionDemandVO;
import com.wing.order.service.DistributionDemandDetailService;
import com.wing.order.service.DistributionDemandService;
import com.wing.product.model.entity.*;
import com.wing.product.model.response.ProductDetailVO;
import com.wing.product.model.response.ProductVO;
import com.wing.product.service.ProductDetailService;
import com.wing.product.service.ProductService;
import com.wing.warehouse.model.response.WarehouseVO;
import com.wing.warehouse.service.WarehouseService;
import com.wing.web.annotation.RequestObjectFieldIgnore;
import com.wing.web.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

/**
 *
 * @author
 */
@Validated
@Api(value = "Admin-上货计划管理", tags = "#/cabinet/cabinetLoadPlan")
@RestController("cabinetLoadPlanController")
@RequestMapping("cabinet/admin/cabinetLoadPlan")
@RequiredArgsConstructor
@Slf4j
public class CabinetLoadPlanController {

    private final CabinetLoadPlanService cabinetLoadPlanService;
    @Autowired
    private DistributionDemandService distributionDemandService;
    @Autowired
    private DistributionDemandDetailService distributionDemandDetailService;
    @Autowired
    private CabinetService cabinetService;
    @Autowired
    private CabinetCargoLaneService cabinetCargoLaneService;
    @Autowired
    private WarehouseService warehouseService;
    @Autowired
    private ProductService productService;
    @Autowired
    private ProductDetailService productDetailService;
    @Autowired
    private CabinetLoadPlanDetailService cabinetLoadPlanDetailService;

    @ApiOperation(value = "查询所有上货计划", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "desc", example = "desc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "code", value = "编号", defaultValue = "", example = "", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<CabinetLoadPlanVO> list(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "desc") String order
            ,String code
            ,Long distributionDemandId
    ){
        Page<CabinetLoadPlan> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }
        //搜索
        if (StringUtils.isNotBlank(code)) {
            params.put("code", code);
        }
        params.put("distributionDemandId",distributionDemandId);
        params.put("enterpriseCode", JwtUtils.getEnterpriseCode());
        Page<CabinetLoadPlanVO> list = cabinetLoadPlanService.pageList4app(pg, params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "添加上货计划", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @PostMapping("/add")
    public JsonResult add(@Validated(CabinetLoadPlanForm.Add.class) @RequestBody CabinetLoadPlanForm cabinetLoadPlanForm) {
        try {
            if (cabinetLoadPlanService.add(cabinetLoadPlanForm) > 0) {
                return JsonResult.success("添加成功");
            }
            return JsonResult.fail("添加失败");
        } catch (BusinessException e) {
            return JsonResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            return JsonResult.fail(e.getMessage());
        }
    }

    /*@ApiOperation(value = "修改上货计划", notes = "修改")
    @PutMapping("/update")
    public JsonResult update(@Validated(CabinetLoadPlanForm.Update.class) CabinetLoadPlanForm cabinetLoadPlanForm) {
        CabinetLoadPlan cabinetLoadPlan = cabinetLoadPlanService.getById(cabinetLoadPlanForm.getId());
        if(cabinetLoadPlan == null){
        return JsonResult.fail("修改失败！");
        }
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(CabinetLoadPlan.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(cabinetLoadPlanForm, cabinetLoadPlan, copyOptions);
        if (cabinetLoadPlanService.updateById(cabinetLoadPlan)) {
            return JsonResult.success("修改成功！");
        }
        return JsonResult.fail("修改失败！");
    }

    @ApiOperation(value = "删除上货计划", notes = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cabinetLoadPlanId", value = "上货计划id", required = true, dataType = "Integer", paramType = "path")
    })
    @DeleteMapping("/{id}" )
    public JsonResult delete(@PathVariable("id") Long cabinetLoadPlanId) {
        if (cabinetLoadPlanService.removeById(cabinetLoadPlanId)) {
            return JsonResult.success("删除成功");
        }
        return JsonResult.fail("删除失败");
    }*/

    @ApiOperation(value = "查询所有配货需求订单表", notes = "添加补货上货计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            , @ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            , @ApiImplicitParam(name = "sort", value = "排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "order", value = "排序规则(asc:正序, desc:倒序)", defaultValue = "desc", example = "desc", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "distCode", value = "配货订单编号", defaultValue = "", example = "", dataType = "String", paramType = "query")
    })
    @GetMapping("/distributionDemandList")
    public PageResult<DistributionDemandVO> distributionDemandList(
            @RequestParam(defaultValue = "1") Integer page
            , @RequestParam(defaultValue = "10") Integer limit
            , @RequestParam(defaultValue = "create_time") String sort
            , @RequestParam(defaultValue = "desc") String order
            , String distCode
    ) {
        Page<DistributionDemand> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }
        if (StringUtils.isNotBlank(distCode)) {
            params.put("distCode", distCode);
        }
        //搜索
        Page<DistributionDemandVO> list = distributionDemandService.pageList4app(pg, params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有配货需求计划明细表", notes = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "demandId", value="配货订单ID", defaultValue = "", example = "", dataType = "Long", paramType = "query")

    })
    @GetMapping("/distributionDemandDetailList")
    public PageResult<DistributionDemandDetailVO> distributionDemandDetailList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,Long demandId
            ,String distCode
            ,Long warehouseId
            ,Integer isLoadPlanFinish
    ){

        Page<DistributionDemandDetailVO> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }

        //搜索
        if(demandId != null){
            params.put("demandId", demandId);
        }
        if(StringUtils.isNotBlank(distCode)){
            params.put("distCode", distCode);
        }
        if(warehouseId != null){
            params.put("warehouseId", warehouseId);
        }
        if(isLoadPlanFinish != null){
            params.put("isLoadPlanFinish", isLoadPlanFinish);
        }

        IPage<DistributionDemandDetailVO> list = distributionDemandDetailService.pageList4app(pg,params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有刀柜", notes = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            , @ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            , @ApiImplicitParam(name = "sort", value = "排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "order", value = "排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "cabinetTypeId", value = "刀柜类型ID", defaultValue = "cabinetTypeId", example = "cabinetTypeId", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "cabinetBrandId", value = "刀柜品牌id", defaultValue = "cabinetBrandId", example = "cabinetBrandId", dataType = "String", paramType = "query")
            , @ApiImplicitParam(name = "status", value = "状态", defaultValue = "status", example = "status", dataType = "Integer", paramType = "query")
            , @ApiImplicitParam(name = "code", value = "刀柜编码", defaultValue = "code", example = "code", dataType = "String", paramType = "query")
    })
    @GetMapping("/cabinetList")
    public PageResult<CabinetVO> cabinetList(
            @RequestParam(defaultValue = "1") Integer page
            , @RequestParam(defaultValue = "10") Integer limit
            , @RequestParam(defaultValue = "create_time") String sort
            , @RequestParam(defaultValue = "asc") String order
            , String cabinetTypeId
            , String cabinetBrandId
            , Cabinet.Status status
            , String code
            , Cabinet.CabinetNature cabinetNature
    ) {
        Page<CabinetVO> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }
        //搜索
        if (StringUtils.isNotBlank(cabinetTypeId)) {
            params.put("cabinetTypeId", cabinetTypeId);

        }
        if (StringUtils.isNotBlank(cabinetBrandId)) {
            params.put("cabinetBrandId", cabinetBrandId);

        }
        if (Objects.nonNull(status)) {
            params.put("status", status.getValue());

        }
        if (StringUtils.isNotBlank(code)) {
            params.put("code", code);

        }
        if (Objects.nonNull(cabinetNature)) {
            params.put("cabinetNature", cabinetNature);

        }
        Page<CabinetVO> list = cabinetService.pageList4app(pg, params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有刀柜货道", notes = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "code", value = "编号", defaultValue = "", example = "", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "cabCode", value = "刀柜编号", defaultValue = "", example = "", dataType = "String", paramType = "query")

    })
    @GetMapping("/cabinetCargoLaneList")
    public PageResult<CabinetCargoLaneVO> cabinetCargoLaneList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String code
            ,String cabCode
            ,Integer isFilterCargoLane
            ,Long warehouseId
    ){

        Page<CabinetCargoLaneVO> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }

        //搜索
        if (StringUtils.isNotBlank(code)) {
            params.put("code", code);
        }
        if(StringUtils.isNotBlank(cabCode)){
            params.put("cabCode",cabCode);
        }
        if(isFilterCargoLane != null){
            params.put("isFilterCargoLane", isFilterCargoLane);
        }
        if(warehouseId != null){
            params.put("warehouseId",warehouseId);
        }
        Page<CabinetCargoLaneVO> list = cabinetCargoLaneService.pageList4app(pg, params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有仓库", notes = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "code", value = "编码", defaultValue = "", example = "", dataType = "String", paramType = "query")
    })
    @GetMapping("/warehouseList")
    public PageResult<WarehouseVO> warehouseList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String name
            ,String code
    ){
        Page pg=new Page(page,limit);
        Map queryParam=new HashMap();
        queryParam.put("sort",StrUtil.toUnderlineCase(sort));
        queryParam.put("order",order);
        if(StringUtils.isNotBlank(name)){
            queryParam.put("name",name);
        }
        if(StringUtils.isNotBlank(code)){
            queryParam.put("code",code);
        }
        IPage<WarehouseVO> list = warehouseService.pageList4app(pg,queryParam);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有产品明细表", notes = "详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/productDetailList")
    public PageResult<ProductDetailVO> productDetailList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,Long warehouseId
    ){
        Page pg=new Page(page,limit);
        Map queryParam=new HashMap();
        queryParam.put("sort",StrUtil.toUnderlineCase(sort));
        queryParam.put("order",order);
        //搜索
        if(warehouseId != null){
            queryParam.put("warehouseId", warehouseId);
        }
        Page<ProductDetailVO> list = productDetailService.pageList4app(pg, queryParam);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有上货计划明细", notes = "审核,详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/cabinetLoadPlanDetailList")
    public PageResult<CabinetLoadPlanDetailVO> cabinetLoadPlanDetailList(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,Long cabinetLoadPlanId
            ,String type
    ){
        Page pg = new Page(page,limit);
        Map queryParam=new HashMap();
        queryParam.put("sort",StrUtil.toUnderlineCase(sort));
        queryParam.put("order",order);
        //搜索
        if(cabinetLoadPlanId != null){
            queryParam.put("cabinetLoadPlanId", cabinetLoadPlanId);
        }
        if(StringUtils.isNotBlank(type)){
            queryParam.put("type", type);
        }
        Page<CabinetLoadPlanDetailVO> list = cabinetLoadPlanDetailService.pageList4app(pg, queryParam);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

    @ApiOperation(value = "查询所有上货计划明细", notes = "审核,详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/cabinetLoadPlanDetailList4receive")
    public PageResult<CabinetLoadPlanDetailVO> cabinetLoadPlanDetailList4receive(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,Long cabinetLoadPlanId
            ,String type
    ){
        Page pg = new Page(page,limit);
        Map queryParam=new HashMap();
        queryParam.put("sort",StrUtil.toUnderlineCase(sort));
        queryParam.put("order",order);
        //搜索
        if(cabinetLoadPlanId != null){
            queryParam.put("cabinetLoadPlanId", cabinetLoadPlanId);
        }
        if(StringUtils.isNotBlank(type)){
            queryParam.put("type", type);
        }
        Page<CabinetLoadPlanDetailVO> list = cabinetLoadPlanDetailService.pageList4app(pg, queryParam);
        List<CabinetLoadPlanDetailVO> resultList=combine(list.getRecords());

        return new PageResult<>(resultList, list.getTotal());
    }

    private List<CabinetLoadPlanDetailVO> combine(List<CabinetLoadPlanDetailVO> list){
        List<CabinetLoadPlanDetailVO> resultList=new ArrayList<>();
        Map<String,CabinetLoadPlanDetailVO> map=new HashMap();
        for (CabinetLoadPlanDetailVO cabinetLoadPlanDetail:list){
            String key=cabinetLoadPlanDetail.getSkuCode();
            CabinetLoadPlanDetailVO cabinetLoadPlanDetail2=map.get(key);
            if (cabinetLoadPlanDetail2==null){
                cabinetLoadPlanDetail2=cabinetLoadPlanDetail;
                map.put(key,cabinetLoadPlanDetail2);
            }else{
                cabinetLoadPlanDetail2.setQuantity(cabinetLoadPlanDetail2.getQuantity()+cabinetLoadPlanDetail.getQuantity());
            }
        }
        map.keySet().forEach(item->{
            resultList.add(map.get(item));
        });
        return resultList;
    }

    @ApiOperation(value = "上货计划审核", notes = "审核")
    @PostMapping("/audit")
    public JsonResult audit(@RequestParam Long id, @RequestParam CabinetLoadPlan.Status status) {
        try {
            CabinetLoadPlan cabinetLoadPlan = cabinetLoadPlanService.getById(id);
            if(cabinetLoadPlan == null){
                return JsonResult.fail("操作失败");
            }
            cabinetLoadPlan.setStatus(status);
            if (cabinetLoadPlanService.audit(cabinetLoadPlan) > 0) {
                return JsonResult.success("操作成功");
            }
            return JsonResult.fail("操作失败");
        } catch (BusinessException e) {
            log.error("audit load plan fail",e);
            return JsonResult.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error("audit load plan fail",e);
            return JsonResult.fail(e.getMessage());
        }
    }

}
